<!DOCTYPE html>
<uieip type="page" value="login" debug="true" timeout="5000"></uieip>
<uieip type="reg" value="console"></uieip>

<html>

<head>
    <uieip type="file" value="inc" src="/yqwin/easyui/include.txt" cache="true" minute="1440"></uieip>
    <uieip type="file" value="css" src="/yqwin/css/yqwin.min" cache="true"></uieip>
    <uieip type="file" value="js" src="/yqwin/src/yqwin.min" cache="true"></uieip>
    <title>tree edit</title>
    <style>
        body {
            margin: 0px;
        }

        table {
            border-spacing: 0px;
        }
    </style>
</head>

<body>
    <div id="cc" class="easyui-layout" style="width:100%;height:600px;">
        <div data-options="region:'west',title:'部门',split:true" style="width:330px;overflow: hidden;">
            <ul id="tt_org">
            </ul>
        </div>
        <div data-options="region:'center',title:'部门人员'" style="padding:1px;">
            <table id="tb_user" style="width:100%;height: 500px;"></table>
        </div>
    </div>
    <script>
        var dbname = "yqbase";

        var setResizeTime;
        function form_load() {
            onresize();
            $(window).resize(function () {
                onresize();
            });
            var $west = $('#cc').layout("panel", "west");
            $west.panel("options").onResize = function (width, height) {
                if (setResizeTime === undefined) {
                    setResizeTime = setTimeout(function () {
                        console.log("sssss");
                        onresize();
                    }, 100);
                }
            }

            $('#tt_org').yqTree("loadData");
        }

        function onresize() {
            $('#cc').layout('resize', {
                width: window.innerWidth,
                height: window.innerHeight
            });

            var $west = $('#cc').layout("panel", "west");
            $('#tt_org').yqTree("resize", {
                width: $west.width(),
                height: $west.height()
            });

            var $center = $('#cc').layout("panel", "center");
            $("#tb_user").yqDataGrid("resize", {
                width: $center.width(),
                height: $center.height()
            });

            if (!(setResizeTime === undefined)) {
                clearInterval(setResizeTime);
                setResizeTime = undefined;
            };
        }

        function tabs_init() {
            var panels = $('#tab_set').tabs("tabs");
            for (var i = 0; i < panels.length; i++) {
                panels[i].data("loaddata", false);
            }
        }

        function tabs_reseek() {
            tabs_init();
            var tab = $('#tab_set').tabs('getSelected');
            var index = $('#tab_set').tabs('getTabIndex', tab);
            tabs_select(index);
        }

        function tabs_select(index) {
            var panels = $('#tab_set').tabs("tabs");
            if (!panels[index].data("loaddata")) {
                if (index == 0) {
                    $("#tb_user").yqDataGrid("seek", "");
                } else if (index == 1) {
                    $("#tb_admin").yqDataGrid("seek", "");
                }

                panels[index].data("loaddata", true);
            }
        }

        $(function () {
            $.yqDbList({ ajaxUrl: "_db.html" },
                function (data) {
                    if (data.error == 0) {
                        dbname = data.rows[0].name;
                        console.log(data, dbname);
                        init_org();
                    } else {
                        alert(data.info);
                    }
                });
        });

        function init_org() {
            $('#tt_org').yqTree({
                ajaxUrl: "/_db.html",
                dbname: dbname,
                tbname: "hr_org",
                keyId: "sid",
                bindingKeyId: null,
                bindingValue: null,
                pKeyId: "pid",
                pKeyValue: null,

                loadDataType: 2,
                displayMember: "name",
                loadData: false,

                menuType: 3,

                overflowY: true,

                editMode: 2,
                editModeW: 600,
                editModeH: 450,
                editModeNo: -1,

                beforeBindingTitle: function (titles, callback) {
                    //console.log("beforeBindingTitle", titles);
                    callback(titles);
                },
                afterBindingTitle: function () {
                    init_user();
                },

                beforeSetdata: function (data, callback) {
                    //console.log("beforeSetdata", data);
                    callback(data)
                },
                afterSetdata: function (data) {
                    //console.log("afterSetdata", data);
                },
                formatter: function (node) {
                    //menu_type 0 文件夹,1 菜单界面,2 弹出界面
                    var menu_type = node.attributes["menu_type"];
                    if (menu_type === undefined || menu_type == null) {
                        menu_type = 0;
                    }
                    var text = node.text;
                    if (node.text == null) {
                        text = node.attributes["describe"];
                    }

                    return text;
                },
                onClick: function (node) {     //节点点击
                    if (node === null) {
                        $("#tb_user").yqDataGrid("clear");
                        $("#tb_user").yqDataGrid("setBindingValue", null);
                    } else {
                        $("#tb_user").yqDataGrid("setBindingValue", node.id);
                        $("#tb_user").yqDataGrid("seek", "");
                    }
                },
            });
        }

        function init_user() {
            $("#tb_user").yqDataGrid({
                ajaxUrl: "/_db.html",
                dbname: dbname,
                tbname: "hr_org_user_rel",
                keyId: "sid",
                bindingKeyId: "org_id",
                bindingValue: null,

                addWhere: "",
                order: "queue",

                editMode: 3,
                editModeW: 600,
                editModeH: 450,
                editModeNo: 1,
                loadData: false,
                isPage: false,

                isEdit: true,
                copy: true,
                add: true,
                upp: true,
                del: true,
                isdel: false,
                isdelEdit: false,
                move: true,

                editLoadData: true,

                isSimple: false,
                isSeek: false,

                linkField: ["user_id"],

                afterBindingTitle: function () {
                    form_load();
                },
                onBeforeShowEdit: function (titles, action, row, callback) {      //add/upp/move 编辑执行前
                    callback(true, titles, row);      //true 执行编辑
                },
            });
        }
    </script>

</body>

</html>